var sector_li = document.querySelectorAll(".roundness .sector .sector_center"),
    chance_top = document.querySelector(".chance_top p"),
    roundness = document.querySelector(".roundness"),
    jt_p = document.querySelector(".jt p"), cishu = 5,
    data_cj;
// console.log(jt_p);
var xhr3 = new XMLHttpRequest();
xhr3.open("GET", "http://student.0melon0.cn/index/wheel/get_prize_list");
xhr3.send();
xhr3.addEventListener("readystatechange", function () {
    if (this.readyState == 4 && this.status == 200) {
        data = JSON.parse(this.responseText);
        // console.log(data);
        data.data.prize_list.forEach((val, index) => {
            sector_li[index].firstElementChild.innerText = val.name;
            sector_li[index].lastElementChild.firstElementChild.setAttribute("src", val.diagram);
        })
        //点击抽奖
        jt_p.addEventListener("click", () => {
            var xhr4 = new XMLHttpRequest();
            xhr4.open("GET", "http://student.0melon0.cn/index/wheel/draw?phone=13113334351");
            xhr4.send();
            xhr4.addEventListener("readystatechange", function () {
                if (this.readyState == 4 && this.status == 200) {
                    if (cishu == 0) {
                        alert("没机会抽奖了");
                    } else {
                        data_cj = JSON.parse(this.responseText).data.bingo_prize_id;
                        console.log(data_cj);
                        // roundness.style.transform = `rotate(0deg)`;
                        roundness.style.transition = `all 6s`;
                        roundness.style.transform = `rotate(${3600 + (data_cj-1) * 60}deg)`;
                        cishu--;
                        chance_top.innerHTML = `今天还有<span> ${cishu} </span>抽奖机会`;

                        setTimeout(() => {
                        roundness.style.transform = `rotate(0deg)`;
                        }, 7000);
                       
                    }
                }
            })
        })
    }
})


chance_top.innerHTML = `今天还有<span> ${cishu} </span>抽奖机会`;
